﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import flash.text.*;
    import Display.aswingui.*;
    import org.aswing.colorchooser.*;

    public class ToolTipDialogView extends GenericDialogView {

        protected const LABEL_HEIGHT:int = 14;

        protected var m_tooltipWindow:JPanel;
        protected var m_legacyComponentContainer:JPanel;
        protected var m_headerContainer:Container;
        protected var m_notesContainer:Container;
        protected var m_statusContainer:Container;
        protected var m_actionContainer:Container;
        protected var m_headerLabel:JTextField;
        protected var m_notesLabel:JLabel;
        protected var m_statusLabel:JLabel;
        protected var m_actionLabel:JLabel;
        protected var m_titleContainer:JPanel;
        protected var m_titleLabel:JTextField;
        protected var m_titleTextFormat:TextFormat;
        protected var m_componentListContainer:JPanel;
        protected var m_customComponents:Array;
        protected var m_customHeaderComponent:Component;
        protected var m_customNotesComponent:Component;
        protected var m_customStatusComponent:Component;
        protected var m_customActionComponent:Component;
        protected var m_textPanel:JPanel;
        protected var m_borderBufferContainer:JPanel;
        protected var m_componentsOuterContainer:JPanel;
        protected var m_componentsInnerContinaer:JPanel;
        protected var m_imageContainer:JPanel;
        protected var m_schema:ToolTipSchema;
        protected var m_tailContainer:JPanel;
        protected var m_tail:AssetPane;
        protected var m_margins:Insets;

        public function ToolTipDialogView(_arg1:Dictionary, _arg2:ToolTipSchema, _arg3:String="", _arg4:String="", _arg5:int=0, _arg6:Function=null){
            this.m_customComponents = new Array();
            this.m_margins = new Insets(3, 3, 3, 3);
            this.m_schema = _arg2;
            this.m_titleTextFormat = new TextFormat(this.m_schema.titleFontName, this.m_schema.titleFontSize);
            this.m_titleTextFormat.align = TextFormatAlign.CENTER;
            this.m_tooltipWindow = new JPanel(new VerticalLayout(VerticalLayout.CENTER));
            super(_arg1, _arg3, _arg4, _arg5, _arg6);
        }
        override protected function init():void{
            this.makeBackground();
            this.makeCenterPanel();
            ASwingHelper.prepare(this);
        }
        override protected function makeBackground():void{
            m_bgAsset = this.m_schema.backgroundAsset;
        }
        override protected function makeCenterPanel():void{
            this.m_tooltipWindow.removeAll();
            if (this.m_textPanel){
                this.m_textPanel.removeAll();
            };
            if (this.m_tailContainer){
                this.m_tailContainer.removeAll();
            };
            if (this.m_borderBufferContainer){
                this.m_borderBufferContainer.removeAll();
            };
            this.cleanUpLegacyComponents();
            this.cleanUpCustomComponents();
            this.m_titleContainer = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_textPanel = ASwingHelper.makeSoftBoxJPanelVertical(this.m_schema.innerAlign);
            this.m_tailContainer = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_borderBufferContainer = ASwingHelper.makeSoftBoxJPanel(this.m_schema.innerAlign);
            ASwingHelper.setEasyBorder(this.m_borderBufferContainer, this.m_margins.top, this.m_margins.left, this.m_margins.bottom, this.m_margins.right);
            this.m_textPanel.append(this.m_borderBufferContainer);
            this.m_componentsOuterContainer = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.TOP);
            this.m_componentsInnerContinaer = ASwingHelper.makeSoftBoxJPanelVertical(this.m_schema.innerAlign);
            this.m_imageContainer = ASwingHelper.makeSoftBoxJPanelVertical();
            this.m_componentsOuterContainer.append(this.m_imageContainer);
            this.m_componentsOuterContainer.append(this.m_componentsInnerContinaer);
            this.m_borderBufferContainer.append(this.m_componentsOuterContainer);
            this.makeLegacyComponents();
            this.makeCustomComponents();
            this.refreshBackground();
            this.m_tooltipWindow.append(this.m_titleContainer);
            this.m_tooltipWindow.append(this.m_textPanel);
            this.m_tooltipWindow.append(ASwingHelper.verticalStrut(-4));
            this.m_tooltipWindow.append(this.m_tailContainer);
            this.append(this.m_tooltipWindow);
            ASwingHelper.prepare(this.parent);
        }
        protected function makeLegacyComponents():void{
            this.m_legacyComponentContainer = ASwingHelper.makeSoftBoxJPanelVertical(this.m_schema.innerAlign);
            this.m_headerContainer = ASwingHelper.makeSoftBoxJPanel(this.m_schema.innerAlign);
            this.m_notesContainer = ASwingHelper.makeSoftBoxJPanel(this.m_schema.innerAlign);
            this.m_statusContainer = ASwingHelper.makeSoftBoxJPanel(this.m_schema.innerAlign);
            this.m_actionContainer = ASwingHelper.makeSoftBoxJPanel(this.m_schema.innerAlign);
            this.m_statusLabel = new JLabel("");
            this.m_actionLabel = new JLabel("");
            var _local1:ASFont = new ASFont(this.m_schema.bodyFontName, this.m_schema.bodyFontSize, false, false, false, new ASFontAdvProperties(true, AntiAliasType.ADVANCED, GridFitType.PIXEL));
            var _local2:ASColor = new ASColor(this.m_schema.bodyFontColor);
            this.m_headerLabel = ASwingHelper.makeTextField("", this.m_schema.titleFontName, this.m_schema.titleFontSize, this.m_schema.titleFontColor);
            this.m_statusLabel.setFont(_local1);
            this.m_actionLabel.setFont(_local1);
            this.m_headerLabel.filters = this.m_schema.titleFilters;
            this.m_statusLabel.setForeground(_local2);
            this.m_statusLabel.setTextFilters(this.m_schema.bodyTextFilters);
            this.m_actionLabel.setForeground(_local2);
            this.m_actionLabel.setTextFilters(this.m_schema.bodyTextFilters);
            this.m_legacyComponentContainer.append(this.m_headerContainer);
            this.m_legacyComponentContainer.append(this.m_statusContainer);
            this.m_legacyComponentContainer.append(this.m_actionContainer);
            this.m_componentsInnerContinaer.append(this.m_legacyComponentContainer);
        }
        protected function makeCustomComponents():void{
            this.m_componentListContainer = ASwingHelper.makeSoftBoxJPanelVertical(this.m_schema.innerAlign);
            this.m_titleLabel = ASwingHelper.makeTextField("", this.m_schema.titleFontName, this.m_schema.titleFontSize, this.m_schema.titleFontColor);
            this.m_titleLabel.filters = this.m_schema.titleFilters;
            this.m_titleContainer.append(this.m_titleLabel);
            this.m_componentsInnerContinaer.append(this.m_componentListContainer);
        }
        protected function refreshBackground(_arg1:Boolean=false):void{
            this.m_tailContainer.removeAll();
            var _local2:Boolean;
            if (_arg1){
                if (this.m_customComponents.length == 0){
                    _local2 = false;
                };
            };
            if (((m_bgAsset) && (_local2))){
                this.m_textPanel.setBackgroundDecorator(new AssetBackground(m_bgAsset));
            } else {
                this.m_textPanel.setBackgroundDecorator(null);
            };
            if (!this.m_tail){
                this.m_tail = new AssetPane();
            };
            this.m_tail.setAsset((_local2) ? this.m_schema.tailAsset : null);
            this.m_tailContainer.append(this.m_tail);
        }
        public function getJTextField():JTextField{
            return (this.m_titleLabel);
        }
        protected function cleanUpLegacyComponents():void{
            if (((this.m_legacyComponentContainer) && (this.m_legacyComponentContainer.parent))){
                (this.m_legacyComponentContainer.parent as Container).remove(this.m_legacyComponentContainer);
            };
            ASwingHelper.prepare(this.parent);
        }
        protected function cleanUpCustomComponents():void{
            if (this.m_titleContainer){
                this.m_titleContainer.removeAll();
            };
            if (this.m_componentListContainer){
                this.m_componentListContainer.removeAll();
            };
            this.m_customComponents = [];
            ASwingHelper.prepare(this.parent);
        }
        public function setTitle(_arg1:String):void{
            if (_arg1){
                this.m_titleLabel.setText(_arg1);
            } else {
                this.m_titleLabel.setText("");
            };
            TextFieldUtil.formatSmallCaps(this.m_titleLabel.getTextField(), this.m_titleTextFormat);
            ASwingHelper.prepare(this.parent);
        }
        public function setImage(_arg1:Component):void{
            this.m_imageContainer.removeAll();
            if (_arg1){
                this.m_imageContainer.append(_arg1);
            };
            ASwingHelper.prepare(this.parent);
        }
        public function setCustomComponentsList(_arg1:Array):void{
            var _local2:Component;
            this.cleanUpLegacyComponents();
            this.m_customComponents = _arg1;
            this.m_componentListContainer.removeAll();
            for each (_local2 in this.m_customComponents) {
                this.m_componentListContainer.append(_local2);
            };
            ASwingHelper.prepare(this.parent);
        }
        public function setLegacyComponentsList(_arg1:IToolTipTarget):void{
            this.cleanUpCustomComponents();
            this.m_borderBufferContainer.append(this.m_legacyComponentContainer);
            ASwingHelper.prepare(this.parent);
        }
        public function finalize():void{
            this.refreshBackground(true);
            ASwingHelper.prepare(this.parent);
        }
        public function refreshSchemaFormatting(_arg1:ToolTipSchema):void{
            this.m_schema = _arg1;
            this.m_titleTextFormat = new TextFormat(this.m_schema.titleFontName, this.m_schema.titleFontSize);
            this.m_titleTextFormat.align = TextFormatAlign.CENTER;
            this.makeBackground();
            this.makeCenterPanel();
            ASwingHelper.prepare(this.parent);
        }
        public function setHeader(_arg1:String):void{
            var _local2:TextFormat;
            if (_arg1 != null){
                this.m_headerLabel.setText(_arg1);
                _local2 = new TextFormat(this.m_schema.titleFontName, this.m_schema.titleFontSize);
                _local2.align = this.m_schema.stringAlignment;
                TextFieldUtil.formatSmallCaps(this.m_headerLabel.getTextField(), _local2);
            } else {
                this.m_headerLabel.setText("");
            };
            this.replaceComponent(this.m_headerContainer, this.m_headerLabel);
        }
        public function setNotes(_arg1:String):void{
        }
        public function setStatus(_arg1:String, _arg2:uint=0xFFFFFF):void{
            this.m_statusLabel.setText(_arg1);
            this.m_statusLabel.setForeground(new ASColor(_arg2));
            this.replaceComponent(this.m_statusContainer, this.m_statusLabel);
        }
        public function setCallToAction(_arg1:String):void{
            this.m_actionLabel.setText(_arg1);
            this.replaceComponent(this.m_actionContainer, this.m_actionLabel);
        }
        private function replaceComponent(_arg1:Container, _arg2:Component):void{
            _arg1.removeAll();
            _arg1.append(_arg2);
            ASwingHelper.prepare(_arg1);
        }

    }
}//package Display 
